package cn.wonderland.user.dto;

import cn.wonderland.basic.util.MD5Utils;
import cn.wonderland.basic.util.StrUtils;
import cn.wonderland.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class PhoneRegisterDto {

    @NotBlank(message = "电话号码不能为空！")
    private String phone;
    @NotBlank(message = "确认密码不能为空！")
    private String passwordRepeat;
    @NotBlank(message = "密码不能为空！")
    private String password;
    @NotBlank(message = "短信验证码不能为空！")
    private String smsCodeValue;

    public User getUser() {
        // 盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 密码
        String pwd = MD5Utils.encrypByMd5(salt + this.password);

        return User.
                builder()
                .phone(this.phone)
                .state(1)
                .createtime(new Date())
                .password(pwd)
                .salt(salt)
                .username(this.phone)
                .build();
    }
}
